<!--
  * 公司列表
  *
  * @Author:    1024创新实验室-主任：卓大
  * @Date:      2022-08-15 20:15:49
  * @Wechat:    zhuda1024
  * @Email:     lab1024@163.com
  * @Copyright  1024创新实验室 （ https://1024lab.net ），Since 2012
-->
<template>
  <a-form class="smart-query-form">
    <a-row class="smart-query-form-row">
      <a-form-item label="学校编号" class="smart-query-form-item" v-privilege="'system:sign:queryPage'">
        <!-- <a-input style="width: 300px" v-model:value="queryForm.registerschool" placeholder="请输入编号" />F -->
        <a-select
          v-model:value="queryForm.registerSchool"
          show-search
          style="width: 300px"
          placeholder="请输入编号"
          :options="schooleOptions"
          :filterOption="filterOption"
        >
        </a-select>
      </a-form-item>

      <!-- <a-form-item label="审核状态" class="smart-query-form-item">
                <a-select v-model:value="queryForm.isPass" style="width: 300px" :options="[
                    { value: 0, label: '待审核' },
                    { value: 1, label: '通过' },
                    { value: 2, label: '未通过' },
                ]"></a-select>
            </a-form-item> -->

      <a-form-item class="smart-query-form-item smart-margin-left10">
        <a-button-group>
          <a-button type="primary" @click="onSearch" v-privilege="'system:sign:queryPage'">
            <template #icon>
              <SearchOutlined />
            </template>
            查询
          </a-button>
          <a-button @click="resetQuery" v-privilege="'system:sign:queryPage'">
            <template #icon>
              <ReloadOutlined />
            </template>
            重置
          </a-button>
          <a-button type="primary" @click="downloadFile"> 下载 </a-button>
          <a-button type="primary" @click="downloadFile2"> 下载附件 </a-button>
        </a-button-group>
      </a-form-item>
    </a-row>
  </a-form>

  <a-card size="small" :bordered="false" :hoverable="true">
    <a-row class="smart-table-btn-block">
      <div class="smart-table-operate-block"></div>
      <div class="smart-table-setting-block">
        <TableOperator v-model="columns" :tableId="TABLE_ID_CONST.TEACHERTION.REGISTRATIONrEVIEW" :refresh="ajaxQuery" />
      </div>
    </a-row>

    <a-table
      :scroll="{ x: 1300 }"
      size="small"
      :dataSource="tableData"
      :columns="columns"
      rowKey="employeeId"
      :pagination="false"
      :loading="tableLoading"
      bordered
      :row-selection="{ selectedRowKeys: selectedRowKeyList, onChange: onSelectChange }"
    >
      <template #bodyCell="{ column, record, text }">
        <!-- <template v-if="column.dataIndex === 'political'">
                
                    {{ politicalList[record.political] }}
                </template>
        <template v-if="column.dataIndex === 'marital'">

                    {{ maritalList[record.marital] }}
                </template> -->
        <template v-if="column.dataIndex === 'gender'">
          {{ record.gender == 1 ? '男' : '女' }}
        </template>
        <template v-if="column.dataIndex === 'ethnicGroupId'">
          {{ ethnicGroupList[record.ethnicGroupId - 1] }}
        </template>
        <!-- <template v-if="column.dataIndex === 'registerType'">

                    {{ registerTypeList[record.registerType] }}
                </template> -->

        <template v-if="column.dataIndex === 'action'">
          <div class="smart-table-operate">
            <!-- <a-button v-if="record.isPass === 0" @click="examine(record.employeeId)" size="small" 
                            type="link">审核</a-button> -->
            <a-button @click="detail(record.employeeId)" size="small" type="link">详情</a-button>
          </div>
        </template>
      </template>
    </a-table>

    <div class="smart-query-table-page">
      <a-pagination
        showSizeChanger
        showQuickJumper
        show-less-items
        :pageSizeOptions="PAGE_SIZE_OPTIONS"
        :defaultPageSize="queryForm.pageSize"
        v-model:current="queryForm.pageNum"
        v-model:pageSize="queryForm.pageSize"
        :total="total"
        @change="ajaxQuery"
        @showSizeChange="ajaxQuery"
        :show-total="(total) => `共${total}条`"
      />
    </div>
    <!-- <EnterpriseOperate ref="operateRef" @refresh="ajaxQuery" /> -->
  </a-card>
  <DetailForm ref="detailFormRef"></DetailForm>
</template>
<script setup>
  import { reactive, ref, onMounted } from 'vue';
  import { message, Modal } from 'ant-design-vue';
  import { registrationReviewApi } from '/@/api/registrationReview/index';
  import { PAGE_SIZE, PAGE_SIZE_OPTIONS } from '/@/constants/common-const';
  import { smartSentry } from '/@/lib/smart-sentry';
  import TableOperator from '/@/components/support/table-operator/index.vue';
  import { TABLE_ID_CONST } from '/@/constants/support/table-id-const';
  import DetailForm from './components/index.vue';
  import { loginApi } from '/@/api/system/login-api';
  import { useUserStore } from '/@/store/modules/system/user';

  // 选择表格行
  const selectedRowKeyList = ref([]);
  //岗位代码
  const jobCodeList = ['教师岗位', '其他专业技术岗位', '管理岗位', '工勤技能岗位', '特设岗位', '无其他岗位'];
  // 政治面貌
  const politicalList = ['中共党员', '中共预备党员', '共青团员', '群众', '其他政治面貌'];
  // 婚姻状况
  const maritalList = ['未婚', '已婚', '离异', '丧偶'];
  // 英语等级
  const englishList = ['一级', '二级', '三级', '四级', '五级', '六级', '七级', '八级', '九级'];
  // 普通话等级
  const mandarinList = ['一级甲等', '一级乙等', '二级甲等', '二级乙等', '三级甲等', '三级乙等'];
  // 教师资格证类别
  const teacherCardTypeList = [
    '幼儿园教师资格',
    '小学教师资格',
    '初级中学教师资格 ',
    '高级中学教师资格',
    '中等职业学校教师资格',
    '中等职业学校实习指导教师资格',
    '高等学校教师资格',
  ];
  // 教师资格证学科
  const SubjectList = ['幼儿园', '小学', '初中', '高中'];
  //学位
  const academicDegreeList = ['学士', '硕士', '博士'];
  // 学历
  const educationList = ['本科', '硕士研究生', '博士研究生'];
  const ethnicGroupList = ref([]);
  const registerTypeList = ref([]);
  // --------------------------- 企业表格 列 ---------------------------

  const columns = ref([
    {
      title: '报名序号',
      dataIndex: 'registerNum',
      width: 150,
    },
    {
      title: '报名学校类别',
      dataIndex: 'registerType',
      width: 120,
    },
    {
      title: '应聘学校学校',
      dataIndex: 'registerSchool',
      width: 120,
    },
    {
      title: '姓名',
      dataIndex: 'actualName',
      width: 80,
      ellipsis: true,
    },
    {
      title: '性别',
      dataIndex: 'gender',
      width: 70,
      ellipsis: true,
    },
    {
      title: '手机号码',
      dataIndex: 'phone',
      width: 100,
    },
    {
      title: '出生年月',
      width: 120,
      dataIndex: 'birthday',
      ellipsis: true,
    },
    {
      title: '民族',
      dataIndex: 'ethnicGroupId',
      width: 80,
    },
    {
      title: '邮箱',
      width: 150,
      dataIndex: 'email',
      ellipsis: true,
    },
    {
      title: '通讯地址',
      width: 100,
      dataIndex: 'mailAddress',
      ellipsis: true,
    },
    {
      title: '邮政编码',
      width: 100,
      dataIndex: 'postalCode',
    },
    {
      title: '户籍所在地',
      width: 160,
      dataIndex: 'houseLocation',
    },
    {
      title: '政治面貌',
      dataIndex: 'political',
      width: 110,
    },
    {
      title: '婚姻状况',
      dataIndex: 'marital',
      width: 100,
    },
    {
      title: '操作',
      dataIndex: 'action',
      fixed: 'right',
      width: 60,
    },
  ]);

  // --------------------------- 查询 ---------------------------
  const queryFormState = {
    // registerschool: '',
    isPass: null,
    pageNum: 1,
    pageSize: PAGE_SIZE,
    searchCount: true,
    registerSchool: useUserStore().registerSchool,
  };
  const queryForm = reactive({ ...queryFormState });
  const tableLoading = ref(false);
  const tableData = ref([]);
  const total = ref(0);

  const filterOption = (input, option) => {
    return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
  };

  function onSearch() {
    queryForm.pageNum = 1;
    ajaxQuery();
  }

  function resetQuery() {
    searchDate.value = [];
    Object.assign(queryForm, queryFormState);
    ajaxQuery();
  }

  async function ajaxQuery() {
    try {
      tableLoading.value = true;
      let responseModel = await registrationReviewApi.queryPage(queryForm);
      const list = responseModel.data.list;
      total.value = responseModel.data.total;
      tableData.value = list;
    } catch (e) {
      smartSentry.captureError(e);
    } finally {
      tableLoading.value = false;
    }
  }

  // --------------------------- 增加、修改、详情 ---------------------------

  const detailFormRef = ref(null);
  function examine(enterpriseId) {
    // detailFormRef.value.showModal(enterpriseId);
    detailFormRef.value.showModal(enterpriseId, 'examine');
  }

  function detail(enterpriseId) {
    detailFormRef.value.showModal(enterpriseId);
  }

  function downloadFile() {
    // axios({
    //     method: 'POST', // 对于文件下载，通常使用GET请求
    //     url: 'http://10.10.1.21:1024/signUp/download', // 替换为实际的ZIP文件下载URL
    //     responseType: 'blob', // 设置为blob以接收二进制数据
    //     data: {
    //         "registerSchool": "上海市崇明区新村小学",
    //         "isPass": 0
    //     }
    // }).then(res=>{
    //     console.log(res, res.headers)
    //     const url = window.URL.createObjectURL(new Blob([res.data], { type: res.headers['content-type'] }));
    //     const link = document.createElement('a');
    //     link.href = url;
    //     // link.setAttribute('download', 'filename.xlsx');
    //     document.body.appendChild(link);
    //     link.click();
    //     document.body.removeChild(link);
    //     URL.revokeObjectURL(url);
    // })
    registrationReviewApi
      .downloadFile({
        employeeIds: selectedRowKeyList.value.length ? selectedRowKeyList.value : null,
        registerSchool: queryForm.registerSchool,
        isPass: 0,
      })
      .then((res) => {
        console.log(res, res.headers);
        const url = window.URL.createObjectURL(new Blob([res.data], { type: res.headers['content-type'] }));
        const link = document.createElement('a');
        link.href = url;
        link.setAttribute('download', '教师招聘报名信息');
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
        URL.revokeObjectURL(url);
      });
  }
  function downloadFile2() {
    registrationReviewApi
      .downloadFile2({
        employeeIds: selectedRowKeyList.value.length ? selectedRowKeyList.value : null,
        registerSchool: queryForm.registerSchool,
        isPass: 0,
      })
      .then((res) => {
        console.log(res, res.headers);
        const url = window.URL.createObjectURL(new Blob([res.data], { type: res.headers['content-type'] }));
        const link = document.createElement('a');
        link.href = url;
        link.setAttribute('download', '附件');
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
        URL.revokeObjectURL(url);
      });
  }
  const schooleOptions = ref([]);
  // 表格选择
  function onSelectChange(selectedRowKeys) {
    selectedRowKeyList.value = selectedRowKeys;
  }
  onMounted(async () => {
    ajaxQuery();
    const res = await loginApi.ethnicGroupSelect();
    ethnicGroupList.value = res.data.data.map((i) => {
      return i.ethnicGroupName;
    });

    const registerType = await loginApi.schoolType();
    registerTypeList.value = registerType.data.rows.map((i) => {
      return i.MC;
    });

    const schooleList = await loginApi.schoolList();
    schooleOptions.value = schooleList.data.map((i) => {
      return { label: i.name, value: i.name };
    });
  });
</script>
